﻿using System;
using System.Text;

namespace BlockOS
{
    [Flags]
    public enum FacingMask : byte
    {
        None = 0,
        Right = 1,
        Top = 2,
        Front = 4,
        Left = 8,
        Bottom = 16,
        Back = 32,
        Positives = Right | Top | Front,
        Negatives = Left | Bottom | Back,
        All = Positives | Negatives,
    }

    public static class FacingMaskUtils
    {
        public static string GetBitmapString(this FacingMask mask)
        {
            StringBuilder builder = new();
            for (byte i = 0; i < 6; i++)
            {
                builder.Append(((byte)mask & (1 << i)) != 0 ? '1' : '0');
            }
            var ans = builder.ToString().ToCharArray();
            Array.Reverse(ans);
            return new string(ans);
        }

        public static FacingMask Opposite(this FacingMask mask)
        {
            if (mask == FacingMask.All) return FacingMask.None;

            var pos = mask & FacingMask.Positives;
            var neg = mask & FacingMask.Negatives;

            return (FacingMask)(((byte)neg >> 3) | ((byte)pos << 3));
        }

        public static FacingMask Inverse(this FacingMask mask)
        {
            return mask ^ FacingMask.All;
        }
    }
}
